﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonLibrary.DataModel.WorkFlow;
using System.Data.SqlClient;
using CommonLibrary.DB;

namespace ServiceApplication.Dao.WorkFlow
{
    public class WfInsvalueDao
    {
        public void AddEntity(List<WfInsvalueEntity> wfiveList)
        {
            string sql = "";
            foreach (var item in wfiveList)
            {
                sql += "INSERT INTO wf_insvalue ([task_id] ,[fieldName] ,[fieldValue] ,[fieldType] ) " +
                    "VALUES (" + item.task_id + ",'" + item.fieldName + "','" + item.fieldValue + "','" + item.fieldType + "');";
            }
            DBExecuteUtil.executeSql(sql);
        }

        public List<WfInsvalueEntity> QueryEntity(string task_id)
        {
            List<WfInsvalueEntity> wfInsvalueEntitys = new List<WfInsvalueEntity>();
            List<SqlParameter> parameterList = new List<SqlParameter>();
            parameterList.Add(new SqlParameter("@task_id", task_id));
            string sql = "select insvalue_id,task_id,fieldName,fieldValue,fieldType from wf_insvalue where task_id=@task_id";

            var dt = DBExecuteUtil.querySqlTable(sql, parameterList.ToArray());
            if (dt.Rows.Count == 0) return null;
            WfInsvalueEntity wfInsvalueEntity;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                wfInsvalueEntity = new WfInsvalueEntity();
                wfInsvalueEntity.insvalue_id = int.Parse(dt.Rows[i][0].ToString());
                wfInsvalueEntity.task_id = int.Parse(dt.Rows[i][1].ToString());
                wfInsvalueEntity.fieldName = dt.Rows[i][2].ToString();
                wfInsvalueEntity.fieldValue = dt.Rows[i][3].ToString();
                wfInsvalueEntitys.Add(wfInsvalueEntity);
            }
            return wfInsvalueEntitys;
        }
    }
}
